在开发或使用别人模块时,偶会出现内存泄露的情况,这个时候在配置文件中配置
worker_processes 1; daemon off; master_process off;
然后使用valgrint调试:
valgrind –leak-check=yes –log-file=valgrind_result_leak –trace-children=yes ./nginx
然后出现如下结果:
==29006== 355,213,312 bytes in 86,722 blocks are possibly lost in loss record 145 of 145
==29006== at 0x4A0610C: malloc (vg_replace_malloc.c:195)
==29006== by 0x42C745: ngx_alloc (ngx_alloc.c:22)
==29006== by 0x41636B: ngx_palloc_large (ngx_palloc.c:223)
==29006== by 0×416476: ngx_palloc (ngx_palloc.c:142)
==29006== by 0x417EC1: ngx_create_temp_buf (ngx_buf.c:22)
==29006== by 0x49F8E9: ngx_tcp_lua_chains_get_free_buf (ngx_tcp_lua_util.c:623)
==29006== by 0x4A518A: ngx_tcp_lua_socket_tcp_receive (ngx_tcp_lua_socket.c:1150)
==29006== by 0x4C27A02: lj_BC_FUNCC (in /usr/local/nginx/luajit1/lib/libluajit-5.1.so.2.0.0)
==29006== by 0x49FB1F: ngx_tcp_lua_run_thread (ngx_tcp_lua_util.c:386)
==29006== by 0x49FCC5: ngx_tcp_lua_wev_handler (ngx_tcp_lua_util.c:517)
==29006== by 0x4A0BBF: ngx_tcp_lua_socket_handle_success (ngx_tcp_lua_socket.c:2009)
==29006== by 0x4A487D: ngx_tcp_lua_socket_read (ngx_tcp_lua_socket.c:1395)
很容易看出,问题出现在ngx_tcp_lua_chains_get_free_buf 获得的内存没有释放。且积累了355M的内存。